const Service = require("egg").Service;

class FileService extends Service {
  async query(params){
    const { app, ctx } = this;
    const {  userId } = params;
    const files = await ctx.model.File.findAll({
      where: {
        create_user_id:userId,
      },
    });
    return files;
  }
  // 图片上传后信息存入数据库
  async save(params) {
    const { app, ctx } = this;
    const { filename, fileName, filePath, fileSize, userId } = params;
    const file = new ctx.model.File();
    file.name = fileName;
    file.path = filePath;
    file.size = fileSize;
    file.origin_name=filename;
    file.create_user_id = userId;
    await file.save();
    return { fileName, fileSize, filePath };
  }

}
module.exports = FileService;
